package com.sanalkitaplik.hibernateutil;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import com.sanalkitaplik.packageclassdto.AdminAuthorizationGroupsDTO;
import com.sanalkitaplik.packageclassdto.AdminInfoDTO;


public class Connect {
	
	    public Connect(){
	    	
	    }   

	    public static Connection getConnection()
	    {
	        Connection conn = null;
	        
	        try{
	           DriverManager.registerDriver (new com.ibm.db2.jcc.DB2Driver());
	           conn = DriverManager.getConnection("jdbc:db2j:net://localhost:50000/SNLKTPLK","db2inst1","123456");
	        }
	        catch (Exception e){
	            e.printStackTrace();        
	        }  
	        return conn;
	    }
	    
	    public static void main(String[] args) throws SQLException{
	    	Session s = null;
	    	Transaction t = null;
	    	try{
	    		s = SessionFactoryBuilder.getSessionFactory().openSession();
		    	t = s.beginTransaction();
		    	AdminAuthorizationGroupsDTO arg0 = new AdminAuthorizationGroupsDTO();
		    	arg0.setGroup_name("<asfz");
		    	s.save(arg0);System.out.println("b1");
		    	//t.commit();System.out.println("b2");
	    	}
	    	catch(Exception e){System.out.println("b3");
	    		if(t!=null)
	    			t.rollback();
	    	}
	    	finally{System.out.println("b4");
	    		//s.flush();
	    		s.close();
	    	}
	    	
	    	
	    }
}








//	    public static void job1() throws SQLException{
//	    	
//	    	Statement stmt = null;
//     	    try 
//            {   
//                String sql =  " DELETE FROM MERVE WHERE ID>3 "; 	                
//                conn = getConnection();
//                stmt = conn.createStatement();
//                stmt.executeUpdate(sql);  
//	                String sqlYazilim = " SELECT * FROM MERVE ";	
//	                ResultSet rs = stmt.executeQuery(sqlYazilim);
//		                while(rs.next()){
//		                	int idNumber = rs.getInt("ID");
//		                	System.out.println(idNumber);
//		                	String name = rs.getString("NAME");
//		                	System.out.println(name);
//		                	String surname = rs.getString("SURNAME");
//		                	System.out.println(surname);
//		                }	                
//            }
//            finally 
//            {
//                try {
//                    if (stmt!=null) stmt.close(); stmt = null;
//                    if (conn!=null) conn.close(); conn= null;
//                }
//                
//                catch (Exception ex) {
//                    ex.printStackTrace();
//                } 
//            }
//	    }
//	  public static void main(String[] args) throws Exception{
//		  job1();
//	  }
//	     
